package prototype;

public class OrderFactory {

    public void oldMakeType(IOrder order) {
        int number = order.getOrderNumber();
        System.out.println("原订单地址内存地址: " + order.hashCode());

        while (number > 0) {

            if (order instanceof PersonOrder) {
                PersonOrder personOrder = (PersonOrder) order;
                PersonOrder tempOrder = new PersonOrder();

                tempOrder.setOrderNumber(number > 1000 ? 1000 : number);
                tempOrder.setOrderName(personOrder.getOrderName());

                System.out.println("订单  name: " + tempOrder.getOrderName() + "; number: " + tempOrder.getOrderNumber() + "; temp内存地址: " + tempOrder.hashCode());
                number -= 1000;

            } else if (order instanceof CompanyOrder) {

            }
        }
    }

    public void newMakeType(IOrder order) {
        int number = order.getOrderNumber();
        System.out.println("原订单地址内存地址: " + order.hashCode());

        while (number > 0) {
            IOrder tempOrder = (IOrder) order.cloneOrder();
            tempOrder.setOrderNumber(number > 1000 ? 1000 : number);
            tempOrder.setOrderName(order.getOrderName());
            number -= 1000;
            System.out.println("订单  name: " + tempOrder.getOrderName() + "; number: " + tempOrder.getOrderNumber() + "; temp内存地址: " + tempOrder.hashCode());

        }
    }
}
